package com.yiquan.comment.dao;

import com.yiquan.comment.pojo.Thumb;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface ThumbDao extends JpaRepository<Thumb,Long>, JpaSpecificationExecutor<Thumb> {


    /**
     * 删除点赞数据
     * @param comment_id
     * @param user_id
     */
    @Query(value="delete from yiquan_comment_thump where comment_id = ?1 and user_id = ?2",nativeQuery=true)
    @Modifying
    public void deleteByCommentIdAndUserId(Long comment_id, Long user_id);


    /**
     * 通过评论id和用户id查询点赞记录
     * @param id
     * @param user_id
     * @return
     */
    @Query(value="select * from yiquan_comment_thump where comment_id = ?1 and user_id=?2 and thump_status=?3",nativeQuery=true)
    Thumb findOneByCommentIdAndUserId(Long commentId, Long user_id, Integer status);

    /**
     * 通过评论id和用户id修改评论的点赞状态
     * @param id
     * @param user_id
     */
    @Query(value="update yiquan_comment_thump set thump_status = ?1 where comment_id = ?2 and user_id = ?3",nativeQuery=true)
    @Modifying
    public void updateThumpStatusByCommentIdAndUserId(Integer status,Long id, Long user_id);


    @Query(value = "select * from yiquan_comment_thump  where user_id = ?1 and comment_id=?2 a",nativeQuery = true)
    Thumb findByCommentIdAndUserId(Long userId,Long commentId);

}
